package com.microcdyUser.controller;
import com.microcdy.sys.pojo.SysOperLog;
import com.microcdyUser.service.SysOperLogService;
import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/****
 * @Author:cdy
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/sysOperLog")
@CrossOrigin
public class SysOperLogController {

    @Autowired
    private SysOperLogService sysOperLogService;

    /***
     * SysOperLog分页条件搜索实现
     * @param sysOperLog
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  SysOperLog sysOperLog, @PathVariable  int page, @PathVariable  int size){
        //调用SysOperLogService实现分页条件查询SysOperLog
        PageInfo<SysOperLog> pageInfo = sysOperLogService.findPage(sysOperLog, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * SysOperLog分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用SysOperLogService实现分页查询SysOperLog
        PageInfo<SysOperLog> pageInfo = sysOperLogService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param sysOperLog
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<SysOperLog>> findList(@RequestBody(required = false)  SysOperLog sysOperLog){
        //调用SysOperLogService实现条件查询SysOperLog
        List<SysOperLog> list = sysOperLogService.findList(sysOperLog);
        return new Result<List<SysOperLog>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Long id){
        //调用SysOperLogService实现根据主键删除
        sysOperLogService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改SysOperLog数据
     * @param sysOperLog
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  SysOperLog sysOperLog,@PathVariable Long id){
        //设置主键值
        sysOperLog.setOperId(id);
        //调用SysOperLogService实现修改SysOperLog
        sysOperLogService.update(sysOperLog);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增SysOperLog数据
     * @param sysOperLog
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   SysOperLog sysOperLog){
        //调用SysOperLogService实现添加SysOperLog
        sysOperLogService.add(sysOperLog);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询SysOperLog数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<SysOperLog> findById(@PathVariable Long id){
        //调用SysOperLogService实现根据主键查询SysOperLog
        SysOperLog sysOperLog = sysOperLogService.findById(id);
        return new Result<SysOperLog>(true,StatusCode.OK,"查询成功",sysOperLog);
    }

    /***
     * 查询SysOperLog全部数据
     * @return
     */
    @GetMapping
    public Result<List<SysOperLog>> findAll(){
        //调用SysOperLogService实现查询所有SysOperLog
        List<SysOperLog> list = sysOperLogService.findAll();
        return new Result<List<SysOperLog>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
